package Game.entity;

import Game.functions.Recyclable;
import Game.utils.DrawUtils;

import java.io.IOException;

public class Blast extends Element implements Recyclable {

    String[] paths = {
            "15-Tankwar\\images\\blast_1.gif",
            "15-Tankwar\\images\\blast_2.gif",
            "15-Tankwar\\images\\blast_3.gif",
            "15-Tankwar\\images\\blast_4.gif",
            "15-Tankwar\\images\\blast_5.gif",
            "15-Tankwar\\images\\blast_6.gif",
            "15-Tankwar\\images\\blast_7.gif",
            "15-Tankwar\\images\\blast_8.gif"
    };

    public Blast() {

    }

    public Blast(int x, int y) {
        this.x = x;
        this.y = y;
        this.path = paths[0];
        getSize();
    }

    public Blast(int x, int y, int width, int height) {
        //  x = 墙x- (爆w-墙w)/2
        //  y = 墙y- (爆h-墙h)/2
        super.path = paths[0];
        getSize();
        super.x = x - (super.width - width) / 2;
        super.y = y - (super.height - height) / 2;
    }

    //需要让draw方法每次绘制时都去改变当前爆炸物对象的path属性
    int index = 0;
    boolean flag = false;

    @Override
    public void draw() {
        if (index >= paths.length) {
            index = 0;
            flag = true;
        }
        String path = paths[index++];
        try {
            DrawUtils.draw(path, x, y);
        } catch (IOException e) {
           e.printStackTrace();
        }
    }

    //判断爆炸物是否展示够了一轮
    @Override
    public boolean isOutside() {
        return flag;
    }
}
